package com.bytedance.improvingroad.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.bytedance.improvingroad.R

/**
 * Created by chenxiong
 * date 11/9/21
 */
class RootListAdapter(val list: MutableList<String>): BaseAdapter() {

    override fun getCount() = list.size

    override fun getItem(p0: Int): Any {
        return list[p0]
    }

    override fun getItemId(p0: Int) = p0.toLong()

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        if(p1 == null ) {
            val view = LayoutInflater.from(p2?.context).inflate(R.layout.root_list_item_layout,p2,false)
            val viewHolder = MyViewHolder(view.findViewById(R.id.item_title))
            viewHolder.item.text = list[p0]
            view.tag = viewHolder
            return view
        } else {
            (p1.tag as MyViewHolder).item.text = list[p0]
        }
        return p1
    }
    data class MyViewHolder(
        val item: TextView
    )
}